-- gui_controller.lua

gui_controller = class('gui_controller')

function gui_controller:load()
	self.gui_panels = {}
	
	for i = 1, 3 do
		local temp_panel = gui_panel:new()
		temp_panel.pos = {x = math.random(0, 700), y = math.random(0, 500)}
		temp_panel.size = {w = math.random(200, 400), h = math.random(200, 400)}
		temp_panel:set_background(0, 0, 0)
		temp_panel:set_titlebar_text_colour(0, 0, 0)
		temp_panel:set_border(255, 255, 255)
		temp_panel:set_string("Window "..i)
		
		for i = 1, math.random(1, 5) do
			local temp_checkbox = gui_checkbox:new()
			temp_checkbox.pos = {x = 10, y = 10 + (i * 20)}
			
			local temp_label = gui_label:new()
			temp_label.pos = {x = 32, y = 11 + (i * 20)}
			temp_label:set_colour(255, 255, 255)
			temp_label:set_string("Checkbox "..i)
			
			temp_panel:add_element(temp_checkbox)
			temp_panel:add_element(temp_label)
		end 
	
		table.insert(self.gui_panels, temp_panel)
	end	
end

function gui_controller:draw()
	-- Cycle through all the GUI elements and draw them
	for i, v in ipairs(self.gui_panels) do
		if v.visible then
			v:draw()
		end
	end
end

function gui_controller:update(dt)
	-- Cycle through all the GUI elements and update each
	for i, v in ipairs(self.gui_panels) do
		v:update(dt)
	end
end

function gui_controller:mousepressed(x, y, button)
	for i, v in ipairs(self.gui_panels) do
		v:mousepressed(x, y, button)
	end
end

function gui_controller:mousereleased(x, y, button)
	for i, v in ipairs(self.gui_panels) do
		v:mousereleased(x, y, button)
	end
end